package org.mozhu.mboot.admin.personal.message.entiity;

import org.mozhu.mboot.core.data.entity.BaseEntity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 个人消息： <br/>
 * 1、收件箱和发件箱内的消息默认365天后被放入垃圾箱 <br/>
 * 2、垃圾箱内的消息30天后自动物理删除 <br/>
 * 3、垃圾箱内的消息只有只有当收件人和发件人 把消息都从垃圾箱中删除后才能物理删除 <br/>
 * 4、收藏箱的不能删除 <br/>
 * 如果消息是草稿 那么收件人状态是null
 * <p/>
 */
@Entity
@Table(name = "personal_message")
public class Message extends BaseEntity {

	private static final long serialVersionUID = -8280132196524783240L;

	/**
	 * 消息发送者Id
	 */
	@Column(name = "sender_id")
	private Long senderId;

	/**
	 * 消息接收者id
	 */
	@Column(name = "receiver_id")
	private Long receiverId;

	/**
	 * 消息发送时间
	 */
	@Column(name = "send_date")
	private Date sendDate;

	/**
	 * 消息标题
	 */
	@Column(name = "title")
	private String title;

	/**
	 * 消息内容
	 */
	@Column(length = 10000)
	private String content;

	/**
	 * 发件人状态
	 */
	@Column(name = "sender_state")
	@Enumerated(EnumType.STRING)
	private MessageState senderState = MessageState.out_box;
	/**
	 * 发件人状态改变时间 默认发送时间
	 */
	@Column(name = "sender_state_change_date")
	@Temporal(TemporalType.TIMESTAMP)
	private Date senderStateChangeDate;

	// 收件人状态
	@Column(name = "receiver_state")
	@Enumerated(EnumType.STRING)
	private MessageState receiverState = MessageState.in_box;
	/**
	 * 收件人状态改变时间 默认发送时间
	 */
	@Column(name = "receiver_state_change_date")
	@Temporal(TemporalType.TIMESTAMP)
	private Date receiverStateChangeDate;

	/**
	 * 是否已读
	 */
	@Column(name = "is_read")
	private Boolean read = Boolean.FALSE;
	/**
	 * 是否已回复
	 */
	@Column(name = "is_replied")
	private Boolean replied = Boolean.FALSE;

	/**
	 * 父编号
	 */
	@Column(name = "parent_id")
	private Long parentId;

	/**
	 * 父消息编号列表 如1/2/3/4
	 */
	@Column(name = "parent_ids")
	private String parentIds;

	public Long getSenderId() {
		return senderId;
	}

	public void setSenderId(Long senderId) {
		this.senderId = senderId;
	}

	public Long getReceiverId() {
		return receiverId;
	}

	public void setReceiverId(Long receiverId) {
		this.receiverId = receiverId;
	}

	public Date getSendDate() {
		return sendDate;
	}

	public void setSendDate(Date sendDate) {
		this.sendDate = sendDate;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public MessageState getSenderState() {
		return senderState;
	}

	public void setSenderState(MessageState senderState) {
		this.senderState = senderState;
	}

	public Date getSenderStateChangeDate() {
		return senderStateChangeDate;
	}

	public void setSenderStateChangeDate(Date senderStateChangeDate) {
		this.senderStateChangeDate = senderStateChangeDate;
	}

	public MessageState getReceiverState() {
		return receiverState;
	}

	public void setReceiverState(MessageState receiverState) {
		this.receiverState = receiverState;
	}

	public Date getReceiverStateChangeDate() {
		return receiverStateChangeDate;
	}

	public void setReceiverStateChangeDate(Date receiverStateChangeDate) {
		this.receiverStateChangeDate = receiverStateChangeDate;
	}

	public Boolean getRead() {
		return read;
	}

	public void setRead(Boolean read) {
		this.read = read;
	}

	public Boolean getReplied() {
		return replied;
	}

	public void setReplied(Boolean replied) {
		this.replied = replied;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public String getParentIds() {
		return parentIds;
	}

	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}

	public String makeSelfAsParentIds() {
		return (getParentIds() != null ? getParentIds() : "") + getId() + "/";
	}

}
